//
//  CustomTableViewCell.m
//  22--HomeWork QQ音乐界面
//
//  Created by 冀永金 on 16/8/14.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "MVListModel.h"
#import "CustomCollectionCell.h"
#import "JYYNetWorkParser.h"
#import "FirstModel.h"
#import "SecondModel.h"
#import "ListModel.h"
#import "MVModel.h"
#import "MVListModel.h"
#import "LastModel1.h"
@interface CustomTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *collection;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;

@end
@implementation CustomTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
       
        self.titleLabel = [[UILabel alloc]init];
        [self.contentView addSubview:_titleLabel];
        _titleLabel.textAlignment = 1;
      
        _layout = [[UICollectionViewFlowLayout alloc]init];
        _collection = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:_layout];
        [self.contentView addSubview:_collection];
        _collection.delegate = self;
        _collection.dataSource = self;
        [_collection registerClass:[CustomCollectionCell class] forCellWithReuseIdentifier:@"pool"];
        _collection.scrollEnabled = NO;
        _collection.backgroundColor = [UIColor whiteColor];
                
        
    }
    return self;
}
-(void)layoutSubviews {
    [super layoutSubviews];
    self.titleLabel.frame = CGRectMake(self.bounds.size.width / 2 - 100, 20, 200, 50);
    _collection.frame = CGRectMake(0, 80, self.bounds.size.width, 650);
    _layout.minimumLineSpacing = 10;
    _layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    

}
#pragma mark-------赋值之后必须reloadData一下
-(void)setMvlist:(MVListModel *)mvlist {
    // 重新加载一下*************/
    _mvlist = mvlist;
    [self.collection reloadData];
    self.titleLabel.text = mvlist.name;
  
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return _mvlist.mvlist.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    CustomCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    LastModel1 *model = _mvlist.mvlist[indexPath.row];
    NSLog(@"-----------%@",_mvlist);
    [cell setLastModel:model];
   
    return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 0) {
        return CGSizeMake(self.bounds.size.width - 20, 250);
    }else {
        return CGSizeMake((self.bounds.size.width - 30) / 2, 180);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
